home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1995 April / Internet Tools.iso / ip / ppp / mac / macppp1.1.3-src.hqx / MacPPP1.1.3-src / ppp.h.source < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-19  |  24.8 KB  |  750 lines

  1. /*
  2.  * Include file for MacPPP.  Should be pre-compiled with THINK C
  3.  *    to generate the ppp.h file.
  4.  *
  5.  * Copyright 1992-1993 Merit Network, Inc. and The Regents of the
  6.  *  University of Michigan.  Usage of this source code is restricted
  7.  *  to non-profit, non-commercial purposes.  The source is provided
  8.  *  "as-is", without warranty.
  9.  */
  10. #ifndef _PPP_H
  11. #define _PPP_H
  12. /* uncomment this if you want alot of DebugStr statements */
  13. #define PPP_DEBUG_CHECKS(x)    /* DebugStr(x) */
  14. /* uncomment below if you want to log certain events to memory */
  15. /* #define LOG */
  16. #pragma options(check_ptrs)
  17. /*#include <MacHeaders>*/  /* this causes problems */
  18. #include <Serial.h>
  19. #include <Types.h>        /* in MacHeaders */
  20. #include <THINK.h>        /* in MacHeaders */
  21. #include <Memory.h>        /* in MacHeaders */
  22. #include <Fonts.h>        /* in MacHeaders */
  23. #include <LoMem.h>        /* in MacHeaders */
  24. #include <Desk.h>        /* in MacHeaders */
  25. #include <Notification.h>    /* in MacHeaders */
  26. #include <Resources.h>        /* in MacHeaders */
  27. #include <Timer.h>        /* in MacHeaders */
  28. #include <Dialogs.h>    /* in MacHeaders */
  29. #include <asm.h>        /* in MacHeaders */
  30. #include <TextEdit.h>    /* in MacHeaders */
  31. #include <Errors.h>        /* in MacHeaders */
  32. #include <Controls.h>    /* in MacHeaders */
  33. #include <BDC.h>        /* in MacHeaders */
  34.  
  35. #define    uchar(x) ((unsigned char)(x))
  36.  
  37. #include "MacTCPCommonTypes.h"
  38.  
  39. typedef struct LapInfo    LapInfo;
  40. typedef struct PPPiopb    PPPiopb;
  41. typedef struct sdiopb    sdiopb;
  42. typedef struct TMtimer    TMtimer;
  43.  
  44. #include "headers.h"        /* TCP/IP header structures */
  45. #include "slhc.h"
  46.  
  47. /* iopbs to queue transmit requests */
  48. #define    NUMIOPBS 24
  49.  
  50. /* define size for transmit fifo */
  51. #define XMITQLEN 128
  52.  
  53. /* max size of transmit buffer to give to output driver */
  54. #define TXBUFSIZE 12L
  55.  
  56. /* size for receive buffer (to get data from serial driver with PBRead) */
  57. #define RXBUFSIZE 256
  58.  
  59. /* size for receive driver input buffer */
  60. /* this needs to be somewhat large for slow Macs to run at higher speeds */
  61. #define SDINBUFLEN 1800
  62.  
  63. #define PARAM_DOWN    0x81
  64. #define PARAM_UP    0x82
  65.  
  66. #define TASK_QUEUED 0x8000
  67.  
  68. /* Lap Transition events */
  69. #define    TransitionOpen  0L
  70. #define    TransitionClose 2L
  71.  
  72. /* Basic buffer structure */
  73. struct bufheader {
  74.     b_8        *dataptr;    /* pointer to start of data */
  75.     int        length;        /* length of data */
  76. };
  77.  
  78. #define    YANKBYTE(bufptr)\
  79.  (bufptr->length != 0 ? \
  80.  (bufptr->length--, *bufptr->dataptr++) : -1)
  81.  
  82. #define PPP_IP_PROTOCOL     0x0021
  83. #define PPP_VJ_COMP_PROTOCOL    0x002D
  84. #define PPP_COMPR_PROTOCOL    0x002D
  85. #define PPP_VJ_UNCOMP_PROTOCOL    0x002F
  86. #define PPP_UNCOMP_PROTOCOL    0x002F
  87. #define PPP_IPCP_PROTOCOL    0x8021
  88. #define PPP_LCP_PROTOCOL    0xC021
  89. #define PPP_PAP_PROTOCOL    0xC023
  90. #define HDLC_ALL_ADDR    0xff    /* HDLC all-station */
  91. #define HDLC_UI            0x03    /* HDLC Unnumbered Information */
  92. #define PPP_HDR_LEN    4    /* Max bytes for PPP/HDLC envelope header */
  93.  
  94. /*
  95.  *  Timer
  96.  */
  97.  
  98. #define NULLTIMER    (struct TMtimer *)0
  99.  
  100. struct TMtimer
  101. {
  102.     TMTask            atm;        /* time manager task struct */
  103.     long            duration;    /* millisecond delay (must be positive) */
  104.     struct fsm_s    *fsm_p;        /* pointer to fsm to which this belongs */
  105.     voidProcPtr        proc;        /* procedure to execute on timeout */
  106.     b_8                state;        /* state of the this timer */
  107. };
  108.  
  109. /* Timer states */
  110. #define TIMER_STOP    0
  111. #define TIMER_RUN    1
  112. #define TIMER_EXPIRE    2
  113.  
  114. struct TMprocess
  115. {
  116.     TMTask            atm;
  117.     union {
  118.         LapInfo            *lap;        /* place to save our lap pointer */
  119.         struct fsm_s    *fsm_p;        /* fsm pointer */
  120.     } tmsavptr;
  121. };
  122.  
  123. /*
  124.  *  PPP characters
  125.  */
  126.  
  127. enum {    PPP_FLAG    =   0x7E,   /* Opening/closing frame flag */
  128.     PPP_ESCAPE    =   0x7D   /* escape next character */
  129. };
  130.  
  131. typedef enum { s_Idle, s_Data, s_Escape, 
  132.                   s_Init, s_Finish, s_SendFCS } HDLCState;
  133.  
  134. #define FCS_INIT    0xFFFF
  135. #define FCS_TERM    0xF0B8
  136. /* config packet header */
  137. struct config_hdr {
  138.     b_8 code;
  139. #define CONFIG_REQ     1
  140. #define CONFIG_ACK     2
  141. #define CONFIG_NAK     3
  142. #define CONFIG_REJ     4
  143. #define TERM_REQ     5
  144. #define TERM_ACK     6
  145. #define CODE_REJ     7
  146. #define PROT_REJ     8
  147. #define ECHO_REQ     9
  148. #define ECHO_REPLY    10
  149. #define DISCARD_REQ    11
  150.  
  151.     b_8 id;
  152.     b_16 len;
  153. };
  154. #define CONFIG_HDR_LEN    4    /* Length of config packet header */
  155.  
  156. /* config option header */
  157. struct option_hdr {
  158.     b_8 type;        /* protocol dependant types */
  159.     b_8 len;
  160. };
  161. #define OPTION_HDR_LEN    2    /* Length of option header */
  162.  
  163. /* Supported Configuration Protocol index */
  164. enum { Lcp, Pap, IPcp, fsmi_Size };
  165.  
  166. /* Protocol Constants needed by State Machine */
  167. struct fsm_constant_s {
  168.     b_16    protocol;        /* Protocol number */
  169.     b_8        fsmi;            /* Finite State Machine index */
  170.     b_8        try_req;        /* # of tries for config request */
  171.     b_8        try_nak;        /* # tries for nak substitutes */
  172.     b_8        try_terminate;    /* # tries for terminate */
  173.     b_8        *option_lengths;    /* ptr to array of option lengths */
  174.     b_8        option_limit;    /* # of options recognized */
  175.     b_8        timeout;        /* Time for timeouts (seconds)*/
  176. };
  177.  
  178. /* FSM states */
  179. enum { fsmINITIAL, fsmSTARTING, fsmCLOSED, fsmSTOPPED, fsmCLOSING, fsmSTOPPING,
  180.         fsmREQ_Sent, fsmACK_Rcvd, fsmACK_Sent, fsmOPENED, fsmState_Size };
  181.  
  182. /* State Machine Control Block */
  183. struct fsm_s {
  184.     b_8        state;            /* FSM state */
  185.     b_8        lastid;            /* ID of last REQ we sent */
  186.     b_8        retry;            /* counter for timeouts */
  187.     b_8        retry_nak;        /* counter for naks of requests */
  188.     LapInfo *lap;            /* place to stuff lap pointer */
  189.     struct    TMtimer timer;
  190.     struct    fsm_constant_s pdc;    /* protocol dependent constants */
  191.     void    *pdv;            /* pointer to protocol dependent variables */
  192. };
  193.  
  194. /* Link Phases */
  195. enum {
  196.     pppDEAD = 0,    /* Link Dead, Waiting for physical layer */
  197.     pppESTABLISH,    /* Link Establishment (LCP) phase */
  198.     pppAUTHENTICATE,    /* Authentication Phase */
  199.     pppNETWORK,        /* Network-Layer Protocol Phase */
  200.     pppTERMINATE,    /* Link Termination Phase */
  201.     pppPhase_Size
  202. };
  203.  
  204.                     /* LCP option types */
  205. #define LCP_MRU            0x01
  206. #define LCP_ACCM        0x02
  207. #define LCP_AUTHENT        0x03
  208. #define LCP_QUALITY        0x04
  209. #define LCP_MAGIC        0x05
  210. #define LCP_PFC            0x07
  211. #define LCP_ACFC        0x08
  212. #define LCP_OPTION_LIMIT    0x08    /* highest # we can handle */
  213. #define LCP_N_MRU        (1 << LCP_MRU)
  214. #define LCP_N_ACCM        (1 << LCP_ACCM)
  215. #define LCP_N_AUTHENT    (1 << LCP_AUTHENT)
  216. #define LCP_N_MAGIC        (1 << LCP_MAGIC)
  217. #define LCP_N_QUALITY    (1 << LCP_QUALITY)
  218. #define LCP_N_PFC        (1 << LCP_PFC)
  219. #define LCP_N_ACFC        (1 << LCP_ACFC)
  220.  
  221. /* Table for LCP configuration requests */
  222. struct lcp_value_s {
  223.     b_16    mru;            /* Maximum Receive Unit */
  224.     b_16    authentication;    /* Authentication protocol */
  225.     b_32    accm;            /* Async Control Char Map */
  226.     b_32    magic_number;    /* Magic number value */
  227. };
  228.  
  229. /* for test purposes, accept anything we understand in the NAK */
  230. #define LCP_NEG LCP_N_MRU | LCP_N_ACCM | LCP_N_AUTHENT | LCP_N_PFC | LCP_N_ACFC | LCP_N_MAGIC
  231.  
  232. /* Other configuration option values */
  233. #define LCP_ACCM_DEFAULT    0xffffffffL
  234. #define LCP_MRU_DEFAULT    1500
  235. #define LCP_MRU_HI    1500    /* High MRU limit */
  236. #define LCP_MRU_LO    128        /* Lower MRU limit */
  237.  
  238. #define PPP_OVERHEAD 8        /* room for addr, cntl, protocol and 32-bit FCS */
  239. #define    PPP_BUFSIZE LCP_MRU_HI + PPP_OVERHEAD /* size of buf for PPP packet */
  240.  
  241. #define LCP_NAK_TRY    10        /* NAK attempts */
  242. #define LCP_TERM_TRY 2        /* tries on TERM REQ */
  243.  
  244. /* PAP Parameters */
  245. #define PAPMESSLEN 128
  246. #define PAPUSERLEN 32
  247. #define PAPPASSLEN 32
  248.     /* PAP control block */
  249. struct pap_s {
  250.     char username[PAPUSERLEN];    /* Username for REQ */
  251.     char password[PAPPASSLEN];    /* Password for REQ */
  252.     char message[PAPMESSLEN];    /* message from last ACK/NAK */
  253.     b_8        IOFlag;            /* flag to indicate userio necessary */
  254. };
  255.  
  256.  
  257.                     /* IPCP option types */
  258. #define IPCP_COMPRESS        0x02
  259. #define IPCP_ADDRESSES        0x01
  260. #define IPCP_ADDRESS        0x03    /* newer IP ADDRESS negotiation */
  261. #define IPCP_OPTION_LIMIT    0x03    /* highest # we can handle */
  262. #define IPCP_N_ADDRESS        (1 << IPCP_ADDRESS)
  263. #define IPCP_N_COMPRESS        (1 << IPCP_COMPRESS)
  264. #define IPCP_N_ADDRESSES    (1 << IPCP_ADDRESSES)
  265.  
  266. /* Table for IPCP configuration requests */
  267. struct ipcp_value_s {
  268.     b_32    address;        /* address for this side */
  269.     b_32    other;            /* address for other side */
  270.     b_16    compression;    /* Compression protocol */
  271.     b_16    slots;            /* Slots (0-n)*/
  272.     b_8        slot_compress;    /* Slots may be compressed (flag)*/
  273. };
  274.  
  275. /* for test purposes, accept anything we understand */
  276. #define IPCP_NEG  IPCP_N_ADDRESSES | IPCP_N_COMPRESS | IPCP_N_ADDRESS;
  277.  
  278. #define IPCP_SLOT_DEFAULT     16    /* Default # of slots */
  279. #define IPCP_SLOT_HI         16    /* Maximum # of slots (preallocated) */
  280. #define IPCP_SLOT_LO          1    /* Minimum # of slots */
  281. #define IPCP_SLOT_COMPRESS    0x01    /* May compress slot id */
  282. #define    MAXSLOTS IPCP_SLOT_HI    /* determine how much space to get */    
  283.  
  284. #define IPCP_NAK_TRY    10        /* NAK attempts */
  285. #define IPCP_TERM_TRY    2        /* tries on TERM REQ */
  286.  
  287. /*
  288.  *    local.want:    Options to request and desired values
  289.  *    local.will:    Options to accept in a NAK from remote.
  290.  *    local.work:    Options currently being negotiated.
  291.  *            Value is valid only when negotiate bit is set.
  292.  *    remote.want:    Options to suggest by NAK if not present in REQ.
  293.  *    remote.will:    Options to accept in a REQ from remote.
  294.  *    remote.work:    Options currently being negotiated.
  295.  *            Value is valid only when negotiate bit is set.
  296.  */
  297.  
  298. union value_s {
  299.     struct    lcp_value_s lcp_option;
  300.     struct    ipcp_value_s ipcp_option;
  301. };
  302.  
  303. struct option_s {
  304.     b_16            will_negotiate, want_negotiate;
  305.     union value_s    want;
  306.     b_16            work_negotiate;
  307.     union value_s    work;
  308. };
  309.  
  310. struct proto_s {
  311.     struct    option_s local, remote;
  312. };
  313.  
  314.  /* structure to queue writes */
  315.  
  316. struct PPPiopb {
  317.     QElemPtr    qLink;        /* next in queue */
  318.     short        qType;        /* qType field */
  319.     struct bufheader *bufptr;        /* ptr to buffer */
  320.     struct ipbuf    *ipbuf;        /* ptr to ipbuf */
  321. };
  322.  
  323. /* Data structure for PPP Preferences file */
  324. /* Note: This struct MUST map into the option_s structure !! */
  325.  
  326. struct lcp_will_want {
  327.     b_16    will_negotiate, want_negotiate;
  328.     struct    lcp_value_s want;
  329. };
  330.  
  331. struct lcpconfig {
  332.     struct lcp_will_want local, remote;
  333.     b_8        req_tries;
  334.     b_8        timeout;
  335. };
  336.  
  337. struct ipcp_will_want {
  338.     b_16    will_negotiate, want_negotiate;
  339.     struct    ipcp_value_s want;
  340. };
  341.  
  342. struct ipcpconfig {
  343.     struct ipcp_will_want local, remote;
  344.     b_8        req_tries;
  345.     b_8        timeout;
  346. };
  347.  
  348. #define MAXSLEN 42        /* max string length */
  349. #define NUMCOMMANDS 8    /* number of strings */
  350. #define PREF_VERSION 3    /* version of prefs file */
  351. #define NUMCONFIGS 4    /* number of configurations */
  352. struct ppp_pref {
  353.     b_16    version;        /* version of Preferences file */
  354.     char    portname[32];    /* port name (from CommToolBox) */
  355.     Boolean    hangup;            /* send modem hangup command on close */
  356.     Boolean    use_pulse;        /* use pulse for dialing */
  357.     Boolean quiet;            /* Quiet mode flag */
  358.     Boolean use_term;        /* bring up a terminal window on connection establishment */
  359.     b_16    timeout;        /* idle timeout (minutes), 0 = none */
  360.     b_16    echo;            /* PPP LCP echo interval  0 = off */
  361.     b_16    active_config;    /* active config index */
  362.     b_16    max_config;        /* maximum conifg index */
  363.     b_16    echo_tries;        /* number of echos before down */
  364.     b_16    max_window;        /* maximum window size */
  365. };
  366.  
  367. struct ppp_config {
  368.     struct    lcpconfig    lcpconf;
  369.     struct    ipcpconfig    ipcpconf;
  370.     b_8        pap_retries;                /* number of tries for PAP */
  371.     b_8        pap_timeout;            /* timeout for PAP */
  372.     b_16    connecttimeout;
  373.     b_16    waittimeout;
  374.     b_16    baudrate;        /* port speed */
  375.     Boolean flowctl_on;
  376.     char    config_name[MAXSLEN + 1];        /* configuration name */
  377.     char    defaultid[MAXSLEN + 1];        /* add one for length byte */
  378.     char    defaultpw[MAXSLEN + 1];
  379.     char    modeminit[MAXSLEN + 1];
  380.     char     phonenum[MAXSLEN + 1];
  381.     struct {
  382.         Boolean    sendout;        /* should we send or wait for this string */
  383.         Boolean addreturn;        /* add a carriage return to end of string */
  384.         char    scriptstr[MAXSLEN + 1];    /* script string */
  385.     } commands[NUMCOMMANDS];
  386. };
  387.  
  388. struct IPCONFIG {
  389.     long        version;
  390.     long        flags;
  391.     long        dfl_ip_addr;
  392.     long        dfl_net_mask;
  393.     long        dfl_broadcast_mask;
  394.     long        dfl_gateway_addr;
  395.     unsigned char    server_lap_address[8];
  396.     long        configIPAddr;
  397.     long        configNetMask;
  398.     long        dfl_dyn_low;
  399.     long        dfl_dyn_high;
  400.     char        dfl_zone[33];        /* ### */
  401. /* align to word */
  402.     Byte        load;
  403.     Byte        admin;
  404.     Byte        netLock;
  405.     Byte        subnetLock;
  406.     Byte        nodeLock;
  407.     Byte        filler1;
  408.     long        activeLap;
  409.     long        slot;
  410.     char        filename[33];        /* ### */
  411. };
  412.  
  413. struct icmpEchoInfo {
  414.     unsigned long    echoRequestOut;    /* time when echo req. went out */
  415.     unsigned long    echoReplyIn;    /* time when echo reply received */
  416.     struct rdsEntry    echoedData;    /* data received in response */
  417.     Ptr        options;    /* IP Options */
  418.     unsigned long    userDataPtr;    /* userDataPtr for app stuff */
  419. };
  420.  
  421. typedef struct ipbuf {
  422.     IOParam        iop;        /* MAC OS I/O Param block */
  423.     struct icmpEchoInfo    echoInfo;    /* ping stuff */
  424.     struct ipbuf    *segipb;    /* pointer to segment's IPB if fragmented */
  425.     struct LapInfo    *lap;        /* LAP pointer */
  426.     ProcPtr        lap_ioc;     /* local net completion routine */
  427.     ProcPtr        ip_ioc;        /* IP completion routine */
  428.     ProcPtr        tp_ioc;        /* transport completion routine */
  429.     ProcPtr        data_ioc;    /* data IOC */
  430.     struct wdsEntry    laphdr;        /* local net header */
  431.     struct wdsEntry    ip;        /* IP header */
  432.     struct wdsEntry    tp;        /* TCP/UDP or ICMP header */
  433.     struct wdsEntry    data;        /* TCP/UDP data */
  434.     struct wdsEntry    d1;
  435.     struct wdsEntry    d2;
  436.     struct wdsEntry    d3;
  437.     struct wdsEntry    d4;        /* 8 wds entries plus 0 terminator */
  438.     short        flag;        /* zero terminator to WDS */
  439.     char        packet[];    /* start of variable length pkt */
  440. } ipbuf;
  441.  
  442. struct rdStruct {
  443.     ProcPtr    ph_rp;        /* pointer to "ReadPacket" routine (a4)    */
  444.     ProcPtr    ph_rr;        /* pointer to "ReadRest" routine 2(a4)    */
  445.     long    ph_bytesleft;    /* number of bytes left to read    */
  446.     union {
  447.         struct {    /* storage for standard AppleTalk LAP protocol handler */
  448.             long    phb_a4;        /* used by driver    */
  449.             long    phb_a0;        /* used by driver    */
  450.             long    phb_a1;        /* used by driver    */
  451.             long    phb_a2;        /* used by driver    */
  452.             } phb;
  453.         struct {    /* storage for a buffered LAP interface */
  454.             b_8    *lnb_ptr;    /* pointer to next byte to get from buffer    */
  455.             } lnb;
  456.         struct {    /* storage for a reassembled IP packet */
  457.             struct fragment    *rsmb_fragbuffer;    /* buffer to fragment data buffer */
  458.             b_8    *rsmb_ptr;    /* pointer to next byte to get from buffer */
  459.             long    rsmb_bytesleft;    /* number of bytes left in this buffer */
  460.             long    rsmb_byteoffset;/* offset of next byte in rsm'd pkt */
  461.             } rsm;
  462.         } rdsparm;
  463.     Byte    lapBroadcast;    /* LAP-level broadcast */
  464.     Byte    ipBroadcast;    /* IP-level broadcast */
  465.     struct LapInfo    *lap;
  466.     struct wdsEntry    laphdr;    /* local net header */
  467.     struct wdsEntry    ip;    /* ip header !!! (IPwdsEntry) ???*/
  468.     struct wdsEntry    tp;    /* TCP/UDP or ICMP header */
  469.     struct wdsEntry    data;    /* TCP/UDP data */
  470. };
  471.  
  472. struct sdiopb {
  473.     IOParam        iop;    /* IOPB for serial driver use */
  474.     LapInfo        *lap;    /* ptr to LapInfo */
  475.     };
  476.     
  477. typedef unsigned long (*longProcPtr)();
  478.  
  479. #define BUFOFFSET sizeof(struct bufheader) + sizeof(struct ipheader) + sizeof(struct tcpheader)
  480. #define    BUFFERSIZE PPP_BUFSIZE + BUFOFFSET
  481. #define NUMBUFFERS 4    /* number of buffers to allocate */
  482. #define LCP_ECHO_BUFSIZE 12 /* buffer size for lcp echo requests */
  483.  
  484. struct LapInfo {
  485.     b_32        cur_ip_addr;    /* LAP's IP address */
  486.     b_32        cur_net_mask;    /* LAP's IP net-mask */
  487.     b_32        ip_broadcast_addr;    /* IP's broadcast address */
  488.     struct IPCONFIG    lc;        /* copy of IP LAP cnfg rsrc */
  489.     OSErrProcPtr    lapInit;    /* ptr to LAP init routine */
  490.     OSErrProcPtr    lapOpen;    /* LAP open rtn */
  491.     OSErrProcPtr    lapClose;    /* LAP close rtn */
  492.     voidProcPtr        lapUnload;    /* LAP unload rtn, undoes lapInit */
  493.     OSErrProcPtr    lapAttach;    /* LAP attach PH rtn */
  494.     OSErrProcPtr    lapDetach;    /* LAP detach PH rtn */
  495.     OSErrProcPtr    lapOutput;    /* LAP output rtn */
  496.     OSErrProcPtr    lapControl;    /* LAP control rtn */
  497.     voidProcPtr        lapFault;    /* LAP fault isolation rtn */
  498.     OSErrProcPtr    lapStatistics;    /* LAP statistic reading rtn */
  499.     voidProcPtr        lapConfigure;    /* LAP configuration rtn */
  500.     BooleanProcPtr    lapProbe;    /* send a LAP-specific addr probe pkt */
  501.     BooleanProcPtr    lapRegister;    /* register our IP address on net */
  502.     voidProcPtr        lapFindGateway;    /* LAP-specific way to find gateway  */
  503.     BooleanProcPtr    lapGwyCheck;    /* LAP-specific way to gateway is up */
  504. /* IP Parameters */
  505.     ip_addr        dfl_dns_addr;    /* addr of DNS from config protocol */
  506.     Handle        dnslHndl;    /* handle to DNS config rsrc */
  507.     Ptr            dnsCache;    /* ptr to DNS cache area */
  508.     long        dnsCacheSize;    /* size of cache in bytes */
  509. /* LAP Parameters */
  510.     long        headerSize;    /* LAP header space required */
  511.     long        trailerSize;    /* LAP trailer space required */
  512.     long        outMaxPacketSize;    /* max output packet size */
  513.     long        inMaxPacketSize;    /* max input packet size */
  514.     long        maxDataSize;    /* max size of data packet */
  515.     long        numConnections;    /* number of separate net connections */
  516.     unsigned long    versionFlags;    /* version number flags */
  517.     voidProcPtr    ip_ph;        /* ptr to IP protocol handler */
  518.     Ptr            ipGlobals;    /* ptr to IP's A5 */
  519.     short        link_unit;    /* unit number of link driver */
  520.     Byte        addressConflict;    /* TRUE is address conflict */
  521.     long        lapType;    /* IP LAP hardware type # */
  522.     long        lapAddrLength;    /* size of LAP address field */
  523.     unsigned char     *lapAddrPtr;    /* ptr to LAP address field */
  524.     unsigned long    reserved;    /* MacTCP reserved field */
  525.     /* PPP specific storage */
  526.     Boolean        ok_to_xmit;    /* ok to transmit on serial port */
  527.     Boolean        term_mode;    /* terminal emulation flag */
  528.     int            serinrefnum;    /* serial input ref num */
  529.     int            seroutrefnum;    /* serial output ref num */
  530.     Byte        outbuf[TXBUFSIZE];    /* small transmit buffer */
  531.     Byte        rxbuf[RXBUFSIZE];    /* small receive buffer to get data from driver */
  532.     longProcPtr    transProc;    /* ptr to transition Proc */
  533.     longProcPtr savProc;    /* place to save a copy of transition proc pointer */
  534.     Ptr            LapA4;        /* holder for LAP's A4 */
  535.     HDLCState    read_state;    /* state of PPP receiver */
  536.     HDLCState    write_state;    /* state of PPP transmitter */
  537.     short        echo_count;    /* count of outstanding LCP echo requests */
  538.     short        idle_timer;    /* number of idle minutes */
  539.     short        writerr;    /* error on write. Who knows what */
  540.     short        readerr;    /* receiver errors */
  541.     OSErr        lasterr;    /* rc of last PBRead != noErr */
  542.     short        outofiopbs;    /* write failed; too many dgs q'd */
  543.     short        faults;        /* PPPFault was called. */
  544.     short        OutofBuffers;    /* # of getbuffer failures */
  545.     long        OutTxOctetCount;/* # octets sent */
  546.     long        OutOpenFlag;    /* # of open flags sent */
  547.     short        OutError;        /* # packets with error on send */
  548.     long        InRxOctetCount;    /* # octets received */
  549.     long        InOpenFlag;        /* # of open flags */
  550.     short        InUnknown;        /* # unknown packets received */
  551.     short        InCheckSeq;        /* # packets with bad check sequence */
  552.     short        InFramingErr;    /* # framing errors */
  553.     short        InError;        /* # packets with other error */
  554.     short        InIdleToss;        /* non-flag chars while Idle */
  555.     short        InHeader;        /*  Header errors */
  556.     short        InFrameOvr;        /* frame overrun */
  557.     short        InSoftOvr;        /* software overrun */
  558.     short        InHardOvr;        /* hardware overrun */
  559.     struct bufheader    *bufptr; /* current buffer for receive data */
  560.     char        *rddata;        /* pointer to end of data in rcv. buffer */
  561.     b_8            xbuf[8];        /* small buffer for copying to fifo */
  562.     struct { 
  563.         b_8        block[BUFFERSIZE];
  564.     } blockarray[NUMBUFFERS];    /* storage for memory blocks */
  565.     struct bufheader *buflist;    /* pointer to buffer list */
  566.     struct {                    /* a small buffer for LCP echo requests */
  567.         struct bufheader header;    /* a fake header for the buffer */
  568.         b_8        buffer[LCP_ECHO_BUFSIZE];    /* the actual buffer */
  569.     } lcp_echo_buf;
  570.     QHdr        out_q;            /* q of packets to write */
  571.     QHdr        pppbq;            /* Q of free PPPiopbs */
  572.     PPPiopb        *active;        /* current PPPiopb to transmit */
  573.     PPPiopb        pppiopbs[NUMIOPBS];    /* define storage for iopbs */
  574.     sdiopb        w_iopb;            /* IOPB for serial port writes */
  575.     sdiopb        r_iopb;            /* IOPB for serial port reads */
  576.     cntrlParam    stat_pb;        /* cntrlParam block for status calls */
  577.     struct rdStruct        rds;    /* for passing to ip layer */
  578.     struct ppp_pref    prefdata;    /* Data from Preferences file */
  579.     struct ppp_config configdata;    /* more preferences */
  580.     b_32        PPP_RecvACM;    /* Async Control maps */
  581.     b_32        PPP_XmitACM;
  582.     b_32        PPP_activeACM;    /* current active transmit ACCM */
  583.     b_16        fcstab[256];    /* FCS table for quicker FCS's */
  584.     b_16        XmitFCS;        /* FCS for current transmit frame */
  585.     b_16        RecvFCS;        /* FCS for current rx frame */
  586.     struct    TMprocess    rxp_task;    /* receive processing task structure */
  587.     struct    TMprocess    txp_task;    /* transmit process task structure */
  588.     struct  TMprocess    echo_task;    /* LCP echo process */
  589.     struct    TMprocess    timeout_task;    /* idle timeout process */
  590.     Byte    sdinbuf[SDINBUFLEN]; /* input buffer for serial driver receive */
  591.     b_16    XmitQHead;            /* transmit queue head index */
  592.     b_16    XmitQTail;            /* transmit queue tail index */
  593.     b_16    XmitQSize;            /* transmit queue size */
  594.     Byte    XmitQ[XMITQLEN];    /* transmit queue */
  595.     struct proto_s    lcp_i, ipcp_i;
  596.     struct pap_s    pap_i;
  597.     b_8        ppp_phase;            /* phase of link initialization */
  598.     b_8        ppp_id;                /* id counter for connection */
  599.     b_32    ppp_upsince;        /* Timestamp when Link Opened */
  600.     b_8        ppp_flags;
  601. #define PPP_AP_REMOTE    0x01    /* remote authentication */
  602. #define ECHO_FAIL        0x02    /* LCP echo timeout */
  603. #define IDLE_TIMEOUT    0x04    /* idle timeout */
  604. #define CLOSE_PPP        0x08    /* close PPP flag */
  605.     struct fsm_s ppp_fsm[fsmi_Size];    /* finite state machines */
  606.     struct slcompress    comp;
  607.     struct cstate    rcvslots[MAXSLOTS],txslots[MAXSLOTS];
  608.     b_8        *lcp_option_length_p; /* lcp option lengths */
  609.     struct    lcp_value_s *lcp_default_p;    /* pointer to default option values */
  610.     b_8        *ipcp_option_length_p; /* ipcp options lengths */
  611.     struct    ipcp_value_s *ipcp_default_p;    /* pointer to default option values */
  612. #ifdef LOG
  613.     int        *logp;
  614.     int        log[5*100];
  615.     int        logend;
  616.     int        cushion[10];
  617. #endif
  618. };
  619.  
  620. typedef struct LapStats {
  621.     short    ifType;
  622.     char    *ifString;
  623.     short    ifMaxMTU;
  624.     long    ifSpeed;
  625.     short    ifPhyAddrLength;
  626.     char    *ifPhysicalAddress;
  627.     union {
  628.             char *noarp;
  629.             } AddrXlation;
  630.     short    slotNumber;
  631. };
  632.     
  633. /* Prototypes and declarations for routines */
  634.  
  635. /* lap.c */
  636. OSErr     PPPInit(    LapInfo *, longProcPtr);
  637. OSErr     PPPOpen(    LapInfo *);
  638. OSErr     PPPClose(    LapInfo *);
  639. void    PPPUnload(    LapInfo *);
  640. OSErr     PPPAttachPH(    LapInfo *, voidProcPtr);
  641. OSErr     PPPDetachPH(    LapInfo *);
  642. OSErr     PPPWrite(    LapInfo *, ip_addr, struct ipbuf *);
  643. OSErr     PPPControl(    LapInfo *);
  644. void     PPPFault(    LapInfo *, ip_addr);
  645. void     PPPConfigure(    LapInfo *);
  646. Boolean    PPPProbe(    LapInfo *, ip_addr);
  647. Boolean    PPPRegister(    LapInfo *);
  648. void    PPPFindGW(    LapInfo *);
  649. OSErr     PPPStatistics(    LapInfo *, struct LapStats *);
  650.  
  651. /* misc.c: */
  652. void    AppendStr(unsigned char *, unsigned char *);
  653. struct bufheader *getbuffer();
  654. void    release(struct bufheader *);
  655. void    makeroom(struct bufheader *, b_16);
  656. b_16    yankbuf(struct bufheader *, char *, b_16);
  657. short    yankbyte(struct bufheader *);    /* returns -1 if nothing */
  658. long    yank16(struct bufheader *);    /* returns -1 if nothing */
  659. b_32    yank32(struct bufheader *);    /* returns  0 if nothing */
  660. int        bytecmp(char *, char *, int);
  661. b_16    get16(char *);
  662. b_32    get32(char *);
  663. char    *put16(char *, b_16);
  664. char    *put32(char *, b_32);
  665. void    tcp_window_fix(LapInfo *, struct bufheader *);
  666.  
  667. /* fsm.c */
  668. void    htoncnf(struct config_hdr *, struct bufheader *);
  669. int        ntohcnf(struct config_hdr *, struct bufheader *);
  670. int        ntohopt(struct option_hdr *, struct bufheader *);
  671.  
  672. int        fsm_sendtermreq(struct fsm_s *);
  673. int        fsm_sendtermack(struct fsm_s *, b_8);
  674. void    fsm_reset(struct fsm_s *);
  675. void    fsm_tld(struct fsm_s *);
  676. void    fsm_tlu(struct fsm_s *);
  677. void    fsm_tlf(struct fsm_s *);
  678. void    fsm_tls(struct fsm_s *);
  679. void    fsm_no_action(struct fsm_s *);
  680. int        fsm_no_check(struct fsm_s *, struct config_hdr *, struct bufheader *);
  681. void    fsm_log(struct fsm_s *, char *);
  682. void    fsm_timer(struct fsm_s *);
  683. void    fsm_timeout(void);
  684. int        fsm_send(struct fsm_s *, b_8, b_8, struct bufheader *);
  685. int        fsm_sendreq(struct fsm_s *);
  686. void    fsm_proc(struct fsm_s *, struct bufheader *);
  687. void    fsm_open(struct fsm_s *);
  688. void    fsm_down(struct fsm_s *);
  689. void    fsm_close(struct fsm_s *);
  690. void    fsm_init(struct fsm_s *);
  691.  
  692. /* ppp.c */
  693. void    ppp_ready(LapInfo *);
  694. void    ppp_init(LapInfo *);
  695. int        ppp_iostatus(LapInfo *, int);
  696. void    htonppp(LapInfo *, b_16, struct bufheader *);
  697. int        proc_request(struct fsm_s *, struct config_hdr *, struct bufheader *);
  698. int        proc_ack(struct fsm_s *, struct config_hdr *, struct bufheader *);
  699. int        proc_nak(struct fsm_s *, struct config_hdr *, struct bufheader *);
  700. int        proc_reject(struct fsm_s *, struct config_hdr *, struct bufheader *);
  701. int        option_check(struct bufheader *, struct fsm_s *,
  702.                             struct option_hdr *, int);
  703. void    makeoptions(struct fsm_s *, struct bufheader *, union value_s *, b_16);
  704. void    add_option(struct fsm_s *, struct bufheader *, union value_s *,
  705.                         b_8, b_8, struct bufheader *);
  706. struct bufheader *makereq(struct fsm_s *);
  707.  
  708. /* link.c */
  709. void    link_open(LapInfo *);
  710. void    link_close(LapInfo *);
  711.  
  712. /* asmutil.c */
  713. void    bzero(char *, short);
  714. void    SetLAPPtr(LapInfo *);
  715. LapInfo    *GetLAPPtr(void);
  716. long    seta5(long);
  717. long    geta5(void);
  718. long    seta4(long);
  719. long    geta4(void);
  720. short    set_sr(short);
  721. short    get_sr(void);
  722.  
  723. /* io.c */
  724. ProcPtr hdlcrioc(void);
  725. ProcPtr    hdlcwioc(void);
  726. OSErr    QueueFrame(LapInfo *, struct bufheader *, struct ipbuf *);
  727. PPPiopb *get_iopb(LapInfo *);
  728. OSErr    readpkt(struct rdStruct *, Ptr, long);
  729. long    readrest(struct rdStruct *, Ptr, long);
  730. void    rcvip(LapInfo *, struct bufheader *);
  731. OSErr    xmit(sdiopb *, unsigned char *, long);
  732. void    ProcRcvPPP(void);
  733. void    ProcXmtPPP(void);
  734. void    IOCompleted(LapInfo *, struct ipbuf *);
  735. void    SerComplete(void);
  736. void    SerReadDone(void);
  737.  
  738. /* pap.c */
  739. int        pap_remote(LapInfo *);
  740. void    pap_down(struct fsm_s *);
  741. void    pap_proc(struct fsm_s *, struct bufheader *);
  742. OSErr    pap_userio(struct fsm_s *);
  743.  
  744. /* timer.c */
  745. void    set_timer(TMtimer *, struct fsm_s *, voidProcPtr);
  746. void    start_timer(TMtimer *);
  747. void    stop_timer(TMtimer *);
  748.  
  749. #endif /* _PPP_H */
  750.